﻿@page "/"
@using MaBlaApp.Data
@using Resources.Langs
@inject LoginUserManager loginUserManager
@inject NavigationManager NavManager

<h1>Hello, world!</h1>

Welcome to your new app.

@*<SurveyPrompt Title="How is Blazor working for you?" />*@

<ul class="list-group" style="overflow:auto">
    <li class="list-group-item">
        <a href="testble" class="btn btn-primary btn-sm">测试低功耗蓝牙</a>
    </li>
    <li class="list-group-item">
        <a href="scanqrcode" class="btn btn-primary btn-sm">扫描二维码</a>
    </li>
    <li class="list-group-item">
        <a href="testbaidumap" class="btn btn-primary btn-sm">百度地图定位</a>
    </li>
    <li class="list-group-item">
        <a href="filedialog" class="btn btn-primary btn-sm">打开本机文件和目录对话框</a>
    </li>
    <li class="list-group-item">
        <a href="exportpdf" class="btn btn-primary btn-sm">导出pdf</a>
    </li>
    <li class="list-group-item">
        <a href="selectlang" class="btn btn-primary btn-sm">@AppRes.SelectLang</a>
    </li>

    @if (isAuthenticated)
    {
        <li class="list-group-item d-flex justify-content-between mb-1">
            <small class="align-self-center">您已经登录</small>
            <button class="btn btn-warning btn-sm ms-2" @onclick="Logout">退出登录</button>
        </li>
        <li class="list-group-item">
            <strong>用户信息</strong>
        </li>
        <li class="list-group-item d-flex justify-content-between mb-1">
            <strong>AccessToken</strong>
            <small>@userInfo.AccessToken</small>
        </li>
        <li class="list-group-item d-flex justify-content-between mb-1">
            <strong>RefreshToken</strong>
            <small>@userInfo.RefreshToken</small>
        </li>
        <li class="list-group-item d-flex justify-content-between mb-1">
            <strong>ExpiresIn</strong>
            <small>@userInfo.ExpiresIn</small>
        </li>
        <li class="list-group-item d-flex justify-content-between mb-1">
            <strong>UserId</strong>
            <small>@userInfo.UserId</small>
        </li>
        <li class="list-group-item d-flex justify-content-between mb-1">
            <strong>Username</strong>
            <small>@userInfo.Username</small>
        </li>
        <li class="list-group-item d-flex justify-content-between mb-1">
            <strong>UserRole</strong>
            <small>@userInfo.UserRole</small>
        </li>
    }
    else
    {
        <li class="list-group-item d-flex justify-content-between mb-1">
            <small class="align-self-center">您还没有登录，请先登录</small>
            <a class="btn btn-primary btn-sm ms-2" href="login">登录</a>
        </li>
    }
</ul>

@code {
    private bool isAuthenticated => loginUserManager.IsAuthenticated;
    private LoginUserInfo userInfo => loginUserManager.UserInfo;

    protected override async Task OnInitializedAsync()
    {
        if (!isAuthenticated)
        {
            //没有用户登录信息，跳转到登录页面
            //NavManager.NavigateTo("/login");
        }
    }

    private void Logout()
    {
        loginUserManager.Logout();

        //直接跳转到登录页面
        //NavManager.NavigateTo("/login");
    }
}
